package com.whitedust.top90;

/**
 *
 * @author A
 * @since 2025/11/16 21:05
 */

public class Top89 {
    public int subarraySum(int[] nums, int k) {
        if (nums == null || nums.length == 0) return 0;
        int[] preSum = new int[nums.length+1];
        preSum[0] = 0;
        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            preSum[i+1] = preSum[i] + nums[i];
        }
        for (int i = 0; i < nums.length; i++) {
            for (int j = i; j < nums.length; j++) {
                if (preSum[j+1] - preSum[i] == k) sum++;
            }
        }
        return sum;
    }
}
